#!/bin/bash
set -e

source $(dirname $0)/version

cd $(dirname $0)/..

if [ "$ARCH" != "amd64" ]; then
  exit 0
fi

docker buildx build \
  --platform linux/${ARCH} \
  --build-arg REPO=${REPO} \
  --build-arg TAG=${TAG} \
  --build-arg VERSION=${VERSION} \
  --file package/Dockerfile \
  --tag ${REPO}/system-upgrade-controller:${TAG}-e2e-tests \
  --tag ${REPO}/system-upgrade-controller:${VERSION}-e2e-tests \
  --tag ${REPO}/system-upgrade-controller:latest-e2e-tests \
  --target e2e-tests \
.

docker image save --output ./dist/artifacts/system-upgrade-controller-e2e-tests-${ARCH}.tar \
  ${REPO}/system-upgrade-controller:${TAG}-e2e-tests \
  ${REPO}/system-upgrade-controller:${VERSION}-e2e-tests \
  ${REPO}/system-upgrade-controller:latest-e2e-tests
echo ${REPO}/system-upgrade-controller:${TAG}-e2e-tests >> ./dist/images.txt
echo Built ${REPO}/system-upgrade-controller:${TAG}-e2e-tests

sonobuoy gen plugin \
  --format=junit \
  --image ${REPO}/system-upgrade-controller:${VERSION}-e2e-tests \
  --name system-upgrade-controller \
  --type job \
> ./dist/artifacts/system-upgrade-controller-e2e-tests.yaml
